package org.example.dao;
        import org.example.entity.Student;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.jdbc.core.BeanPropertyRowMapper;
        import org.springframework.jdbc.core.JdbcTemplate;
        import org.springframework.stereotype.Repository;
        import java.util.List;
@Repository
 public class StudentDaoImpl implements StudentDao{
@Autowired
 private JdbcTemplate jdbcTemplate;
@Override
 public void createTableStudent() {
         String sql="create table if not exists Student(id char(50) primary key,name char(50),age int)";
         jdbcTemplate.execute(sql);
         }
@Override
 public int saveStudent(Student student){
         String sql="insert into student(id,name,age) values(?,?,?)";
         int result=jdbcTemplate.update(sql,new Object[]{student.getId(),
         student.getName(),student.getAge()});
         return result;
         }
@Override
 public List<Student> getAllStudent() {
        String sql="select * from student";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(Student.class));
        }
@Override
 public Student getStudentById(String id){
         String sql="select* from student where id=?";
         return jdbcTemplate.queryForObject(sql,new
         BeanPropertyRowMapper<>(Student.class),id);
        }
@Override
 public int updateStudent(Student student){
         String sql="update student set name=?,age=? where id=?";
         return jdbcTemplate.update(sql,student.getName(),student.getAge(),student.getId());
         }
@Override
 public int deleteStudent(String id) {
         String sql="delete from student where id=?";
         return jdbcTemplate.update(sql,id);
         }
         }